#import "Delegate.h"
#include "ViewController.h"

static ViewController *viewController = NULL;

@implementation AppController

- (void) update
{
	if(viewController)
		viewController->Draw();
	
	[glView swapBuffers];
}


- (void) applicationDidFinishLaunching:(UIApplication*)application
{
	CGRect	rect = [[UIScreen mainScreen] bounds];
	
	window = [[UIWindow alloc] initWithFrame:rect];
	
	glView = [[EAGLView alloc] initWithFrame:rect pixelFormat:GL_RGB565_OES depthFormat:GL_DEPTH_COMPONENT16_OES preserveBackbuffer:NO];
	
	[window addSubview:glView];

	[window makeKeyAndVisible];
	
	viewController = new ViewController([[[NSBundle mainBundle] resourcePath] cStringUsingEncoding:NSASCIIStringEncoding]);
	
	[NSTimer scheduledTimerWithTimeInterval:(1.0 / 60.0) target:self selector:@selector(update) userInfo:nil repeats:YES];
}


- (void) dealloc
{
	delete viewController;

	[glView release];
	
	[window release];
	
	[super dealloc];
}


@end
